<?php

namespace App\HttpController\Email;

use App\Utility\Email\MySendMail;
use App\Utility\Email\Smtp;
use EasySwoole\Core\Http\AbstractInterface\Controller;
use Exception;
use EasySwoole\Core\Swoole\Task\TaskManager;
use App\Server\Task\SendEmailTask;

class Email extends Controller {
	/**
	 *
	 * {@inheritdoc}
	 *
	 * @see \EasySwoole\Core\Http\AbstractInterface\Controller::index()
	 */
	public function index() {
		// $this->response()->write(phpinfo());
		$email = $this->request ()->getRequestParam ( "email" );
		if (empty ( $email )) {
			throw new \Exception ( "email is null" );
		}
		$title = $this->request ()->getRequestParam ( "title" );
		if (empty ( $title )) {
			throw new \Exception ( "title is null" );
		}
		$content = $this->request ()->getRequestParam ( "content" );
		if (empty ( $content )) {
			throw new \Exception ( "content is null" );
		}
		
		TaskManager::async ( (new SendEmailTask ( [ 
				'email' => $email,
				'title' => $title,
				'content' => $content 
		] )) );
	}
}

